<?php include('includes/start_session.php'); include('includes/login_required.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
	<title>e-class my courses</title>

	<link rel="stylesheet" href="styles/site.css" type="text/css" />
	<link rel="stylesheet" href="styles/less_padding.css" type="text/css" />
	
	<script src="scripts/scripts.js" type="text/javascript"></script>
</head>
<body onload="same_height()">
	<?php include('includes/header.php') ?>
	<div id="content" class="content_padding">
		<div id="courses">
			<?php
				include('db-api/txt-db-api.php');
				include('includes/course_info.php');
				
				$showButton = false;
				
				function ShowProfessorCourses()
				{
					if($_SESSION['position'] == 'Stud')
						return;
					$db = new Database('Eclass');
					$rs = $db->executeQuery(
						'SELECT Courses.*
						 FROM Courses, ProfessorsCourses
						 WHERE ProfessorName = \'' . $_SESSION['username'] .
						 '\' AND CourseId = Id'
					);
					
					echo '<h4>Μαθήματα που είμαι καθηγητής</h4>';
					if(!$rs->next())
					{
						echo 'Δε βρέθηκαν μαθήματα που να είστε καθηγητής';
						return;
					}
					echo '<ul class="course_list">';
					$flag = true;
					do
					{
						list($id, $name, $description, $subcat) = $rs->getCurrentValues();
						if($flag == true)
						{
							echo '<li class="first_course">';
							$flag = false;
						}
						else
							echo '<li>';

						echo '<div class="course">';
						
						echo '<a href="course.php?id=' . $id . '" class="title">' . $name . '</a>';
						ShowProfessors($id);
						echo '<a class="anchor" href="teach_course.php?action=remove&id=' . $id
							. '">διακοπή παρακολούθησης ως καθηγητής</a>';	
		
						echo '</div>';			
						echo '</li>';
					} while($rs->next());
					echo '</ul>';
				}
				
				function ShowStudentCourses()
				{
					$db = new Database('Eclass');
					$rs = $db->executeQuery(
						'SELECT Courses.*
						 FROM Courses, UsersCourses
						 WHERE UserName = \'' . $_SESSION['username'] .
						 '\' AND CourseId = Id'
					);
					
					echo '<h4>Μαθήματα που έχω δηλώσει</h4>';
					if(!$rs->next())
					{
						echo 'Δε βρέθηκαν μαθήματα που να έχετε δηλώσει';
						echo '<div class="right_align"><a href="#" class="course_anchor">
							Επιστροφή στην κορυφή</a></div>';
						return;
					}
					echo '<ul class="course_list">';
					$flag = true;
					do
					{
						list($id, $name, $description, $subcat) = $rs->getCurrentValues();
						if($flag == true)
						{
							echo '<li class="first_course">';
							$flag = false;
						}
						else
							echo '<li>';

						echo '<div class="course">';
						
						echo '<a href="course.php?id=' . $id . '" class="title">' . $name . '</a>';
						ShowProfessors($id);
						if($_SESSION['position'] != 'Stud')
						{
							echo '<a class="anchor" href="teach_course.php?action=add&id=' . $id
								. '">παρακολούθηση μαθήματος ως καθηγητής</a>';
							echo  '&nbsp;&nbsp;&nbsp;&nbsp;';
						}
						echo '<a class="anchor" href="watch_course.php?action=remove&id=' . $id
							. '">διακοπή παρακολούθησης</a>';
						
						echo '</div>';				
						echo '</li>';
					} while($rs->next());
					echo '</ul>';
					echo '<div class="right_align">';
					echo '<a href="#" class="course_anchor">Επιστροφή στην κορυφή</a>';
					echo '</div>';
				}
				
				$_SESSION['previous_page'] = 'my_courses.php';
            	if(isset($_GET['message']) && $_GET['message'] == '1')
            		echo '<div class="center_align"><span class="success">Η αλλαγή έγινε με επιτυχία</span></div>';
				ShowProfessorCourses();
				ShowStudentCourses();
			?>
		</div>
	</div>
	<?php include('includes/footer.php') ?>
</body>
</html>
